package com.bingquan.java.swing;

import java.awt.*;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;

public class MouseMove {

    private void moveMouse() throws Exception {
        Robot robot = new Robot();
        //设置响应延时
        robot.setAutoDelay(100);
        //鼠标移动到的位置的坐标
        robot.mouseMove(100, 200);

        //鼠标双击事件（按下+释放）
        //InputEvent.BUTTON1_MASK InputEvent.BUTTON2_MASK InputEvent.BUTTON3_MASK 分别代表左中右键
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);

        robot.delay(100);//停顿100ms

        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        //向下滚动5个刻度滑轮:
        robot.mouseWheel(5);
        System.out.println("===控制鼠标移动");
    }

    private void openTestManage() throws Exception {
        Robot robot = new Robot();
        robot.mouseMove(100, 100);
        robot.keyPress(KeyEvent.VK_CONTROL);
        robot.keyPress(KeyEvent.VK_SHIFT);
        robot.keyPress(KeyEvent.VK_ESCAPE);
        robot.keyRelease(KeyEvent.VK_ESCAPE);
        robot.keyRelease(KeyEvent.VK_SHIFT);
        robot.keyRelease(KeyEvent.VK_CONTROL);
        System.out.println("===打开任务管理器");
    }

    /**
     * 获取当前鼠标坐标信息
     */
    private void getMourseInfo() {
        Point location = MouseInfo.getPointerInfo().getLocation();
        double x = location.getX();
        double y = location.getY();
        System.out.println("x = " + x);
        System.out.println("y = " + y);
    }

    public static void main(String[] args) {
        long beginTime = System.currentTimeMillis();
        System.out.println("----------beginTime: " + beginTime);

        MouseMove obj = new MouseMove();
        try {
//            obj.moveMouse();
//            obj.openTestManage();
            obj.getMourseInfo();
        } catch (Exception e) {
            System.out.println("----------error");
        }
        long endTime = System.currentTimeMillis();
        System.out.println("========end: " + endTime);
        System.out.println("consume Time： " + (endTime - beginTime));


    }
}
